package com.easymall.service.impl;

import com.easymall.dao.CategoryDao;
import com.easymall.domain.Category;
import com.easymall.service.CategoryService;
import com.easymall.util.BaseFactory;

import java.sql.SQLException;
import java.util.List;

public class CategoryServiceImpl implements CategoryService {

    private CategoryDao categoryDao;

    @Override
    public void init() throws Exception {
        categoryDao = BaseFactory.getFactory().getInstance(CategoryDao.class);
    }

    @Override
    public boolean saveCategory(Category category) throws SQLException {
        return categoryDao.saveCategory(category);
    }

    @Override
    public boolean deleteCategory(int cid) throws SQLException {
        return categoryDao.deleteCategoryById(cid);
    }

    @Override
    public List<Category> listCategoryAll() throws SQLException {
        return categoryDao.listCategoryAll();
    }

    @Override
    public Category getCategoryById(int cid) throws SQLException {
        return categoryDao.getCategoryById(cid);
    }

    @Override
    public boolean hasCategoryByName(String cname) throws SQLException {
        Category category = categoryDao.getCategoryByName(cname);
        if (null == category) {
            return false;
        }
        return true;
    }

    @Override
    public boolean hasCategoryById(int cid) throws SQLException {
        Category category = categoryDao.getCategoryById(cid);
        if (null == category) {
            return false;
        }
        return true;
    }
}
